using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Web.Core.Objects;
using Web.Core;

public partial class AdminCP_AdminControls_AddEditManufacturer : System.Web.UI.UserControl
{
    public int manID = 0;
    public string header = "";
    string mDo = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        mDo = Request.Params["do"];
        if (mDo != null)
        {
            this.RequiredFieldValidatorName.ErrorMessage = Resources.Lang.Require;
            this.RequiredFieldValidatorUrl.ErrorMessage = Resources.Lang.Require;

            if(Request.Params["mid"]!=null)
                manID = int.Parse(Request.Params["mid"]);   
            switch (mDo)
            {
                case "edit":
                    header = Resources.Lang.Edit;
                    Manufacturer man = Manufacturers.GetManufacturersByID(manID);
                    this.txtName.Text = man.MName;
                    this.txtUrl.Text = man.MURL;
                    break;
                case "add":
                    header = Resources.Lang.Add;
                    break;
                default:
                    break;
            }
        }        
       
    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        string name = "", url = "";
        try
        {
            name = this.txtName.Text;
        }catch { }
        try {
            url = this.txtUrl.Text;
        }catch { }
        if (mDo == "edit")
        {
            Manufacturer man = new Manufacturer(manID, name, url);
            Manufacturers.UpdateManufacturer(man);
        }
        else if (mDo == "add")
        {
            Manufacturer man = new Manufacturer(manID, name, url);
            Manufacturers.InsertManufacturer(man);
        }
        Response.Redirect("Manufacturers.aspx");
    }
}
